<template>
  <div class="menus-manage">
    <!-- 面包屑 -->
    <div class="bread-crumbs">
      <el-breadcrumb separator="/">
        <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item>项目立项</el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <div class="main-middle">
      <el-card class="box-card">
        <!-- 立项信息 -->
        <div class="card-title">立项信息</div>
        <el-form label-width="100px" :model="creatPro" :rules="creatProRules" ref="creatPro" :disabled="showDatas">
          <el-row :gutter="24">
            <el-col :span="8">
              <el-form-item style="margin:0" label="标记转签">
                  <el-radio-group v-model="creatPro.sign" @change="isSigned">
                    <el-radio :label="0">否</el-radio>
                    <el-radio :label="1">是</el-radio>
                  </el-radio-group>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item style="margin:0" label="接收转签">
                <el-radio-group v-model="creatPro.receive" @change="isRelated">
                    <el-radio :label="0">否</el-radio>
                    <el-radio :label="1">是</el-radio>
                  </el-radio-group>
              </el-form-item>
            </el-col>
             <el-col :span="8" v-if="isRelat">
               <!-- 关联项目 -->
              <el-form-item style="margin:0" label="关联项目" prop="related" :rules="[{ required: true, message: '选择关联项目', trigger: 'change' }]">
                <el-select style="width:100%" v-model="creatPro.related">
                  <el-option v-for="sign in signList" :key="sign.id" :label="sign.proName" :value="sign.id"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
           <el-divider></el-divider>
          <el-row :gutter="24">
            <el-col :span="8">
              <!-- 公司 -->
              <el-form-item label="归属公司" prop="compId">
                <el-select style="width:100%" v-model="creatPro.compId">
                  <el-option v-for="item in compList" :key="item.id" :label="item.compName" :value="item.compId"></el-option>
                </el-select>
              </el-form-item>
              <!-- 归属部门 -->
              <el-form-item label="归属部门" prop="deptId">
                <el-select
                  v-model="creatPro.deptId"
                  filterable
                  auto-complete="off"
                  placeholder="请选择"
                  style="width:100%"
                >
                  <el-option
                    v-for="(item,index) in deptIdList"
                    :key="index"
                    :label="item.deptName"
                    :value="item.deptId"
                  ></el-option>
                </el-select>
              </el-form-item>
              <!-- 最终服务客户 -->
              <el-form-item label="最终服务客户" prop="cusId" class="userlevel-box">
                <el-select
                  v-model="creatPro.cusId"
                  filterable
                  auto-complete="off"
                  placeholder="请选择"
                  style="width:100%"
                  @change="selectDeptCode"
                >
                  <el-option
                    v-for="key in cusList"
                    :key="key.id"
                    :label="key.cusName"
                    :value="key.id"
                  ></el-option>
                </el-select>
                <!-- <el-select style="width:100%" clearable filterable v-model="creatPro.cusId">
                  <el-option v-for="key in cusList" :key="key.id" :label="key.cusName" :value="key.id"></el-option>
                </el-select> -->
              </el-form-item>
              <!-- 最终服务客户部门 -->
              <el-form-item label="最终服务客户部门" prop="cusDeptCode" class="userlevel-box">
                <el-select
                  v-model="creatPro.cusDeptCode"
                  filterable
                  auto-complete="off"
                  placeholder="请选择"
                  style="width:100%"
                >
                  <el-option label="无" value></el-option>
                  <el-option
                   v-for="item in cusDeptCodeList"
                    :key="item.deptCode"
                    :label="item.deptName"
                    :value="`${item.deptCode}-${item.deptName}`"
                  ></el-option>
                </el-select>
              </el-form-item>
              <!-- 项目名称 -->
              <el-form-item label="项目名称" prop="proName">
                <el-input v-model="creatPro.proName"></el-input>
              </el-form-item>
              <!-- 项目经理 -->
               <el-form-item label="项目经理"  v-if="!isSign" prop="pmp">
                  <el-autocomplete
                    v-model="creatPro.pmp"
                    :fetch-suggestions="querySearchAsync"
                    placeholder="请输入姓名"
                    @select="handleSelect"
                    style="width:100%;"
                    clearable
                  >
                  <template slot-scope="{ item }">
                    <div class="selName">
                      <span>{{ item.compName }} - {{ item.deptName }}</span>
                      <span>{{ item.userName }}</span>
                      <span>[{{ item.userId }}]</span>
                    </div>
                  </template>
                </el-autocomplete>
                </el-form-item>
            </el-col>
            <el-col :span="8">
              <!-- 项目类型 -->
              <el-form-item label="项目类型" prop="type">
                <el-select style="width:100%" v-model="creatPro.type" @change="changeType">
                  <el-option label="过单项目" value="GD"></el-option>
                  <el-option label="预投入项目" value="YTR"></el-option>
                  <el-option label="正式项目" value="ZS"></el-option>
                </el-select>
              </el-form-item>
              <!-- 服务类型 -->
              <el-form-item label="服务类型" prop="serveType">
                <el-select style="width:100%" v-model="creatPro.serveType">
                  <el-option label="A类驻场服务" value="1"></el-option>
                  <el-option label="A类咨询服务" value="2"></el-option>
                  <el-option label="B类运维/实施服务" value="3"></el-option>
                  <el-option label="C类定制化开发" value="4"></el-option>
                  <el-option label="软件过单" value="5"></el-option>
                  <el-option label="硬件过单" value="6"></el-option>
                </el-select>
              </el-form-item>
              <!-- 项目计划开始时间 -->
              <el-form-item label="项目计划开始时间" prop="cycleStart" class="userlevel-box">
                 <el-date-picker
                  style="width:100%"
                  v-model="creatPro.cycleStart"
                  type="date"
                  placeholder="选择日期">
                </el-date-picker>
              </el-form-item>
              <!-- 项目计划结束时间 -->
              <el-form-item label="项目计划结束时间" prop="cycleEnd" class="userlevel-box">
                 <el-date-picker
                  style="width:100%"
                  v-model="creatPro.cycleEnd"
                  type="date"
                  placeholder="选择日期">
                </el-date-picker>
              </el-form-item>
              <!-- 添加销售/交付负责人 -->
              <el-form-item label="销售/交付负责人" v-if="!isSign" prop="saleUser" class="userlevel-box">
                <el-input v-model="creatPro.saleUser"></el-input>
              </el-form-item>
              <!-- 合同编号 -->
              <el-form-item label="合同编号" v-if="!isSign">
                <el-input v-model="creatPro.contractCode"></el-input>
              </el-form-item>
              <!-- 客户名称 -->
              <!-- <el-form-item label="客户名称" prop="cusId">
                <el-select
                  v-model="creatPro.cusId"
                  filterable
                  auto-complete="off"
                  placeholder="请选择"
                  style="width:100%"
                  @change="selectDeptCode"
                >
                  <el-option
                    v-for="key in cusList"
                    :key="key.id"
                    :label="key.cusName"
                    :value="key.id"
                  ></el-option>
                </el-select>
              </el-form-item> -->
            </el-col>
            <el-col :span="8" v-if="!isSign">
              <!-- 项目周期(月) -->
              <el-form-item label="项目周期(月)" v-if="!isSign" prop="proCycle">
                <el-input v-model="creatPro.proCycle"></el-input>
              </el-form-item>
              <!-- 添加计划投入人数 -->
              <el-form-item label="计划投入人数" v-if="!isSign" prop="expectNum" class="userlevel-box">
                <el-input v-model="creatPro.expectNum"></el-input>
              </el-form-item>
              <!-- 添加计划投入人月 -->
              <el-form-item label="计划投入人月" v-if="!isSign" prop="putInMonth">
                <el-input v-model="creatPro.putInMonth"></el-input>
              </el-form-item>
              <!-- 添加预估成本 -->
              <el-form-item label="预估成本" v-if="!isSign" prop="ygCost">
                <el-input v-model="creatPro.ygCost"></el-input>
              </el-form-item>
              <!-- 添加预估合同额 -->
              <el-form-item label="预估合同额" v-if="isYTR" prop="contractMoney">
                <el-input v-model="creatPro.contractMoney"></el-input>
              </el-form-item>
              <!-- 添加合同预计遣返时间 -->
              <el-form-item label="合同预计遣返时间" v-if="isYTR" prop="contractDate" class="userlevel-box">
                <el-date-picker
                  style="width:100%"
                  v-model="creatPro.contractDate"
                  type="date"
                  placeholder="选择日期">
                </el-date-picker>
              </el-form-item>
              <!-- 客户部门 -->
              <!-- <el-form-item label="客户部门" prop="cusDeptCode">
                <el-select
                  v-model="creatPro.cusDeptCode"
                  filterable
                  auto-complete="off"
                  placeholder="请选择"
                  style="width:100%"
                >
                  <el-option label="无" value></el-option>
                  <el-option
                   v-for="item in cusDeptCodeList"
                    :key="item.deptCode"
                    :label="item.deptName"
                    :value="`${item.deptCode}-${item.deptName}`"
                  ></el-option>
                </el-select>
              </el-form-item> -->
              <!-- 项目周期 -->
              <!-- <el-form-item label="项目周期" v-if="!isSign" prop="cycle">
                <el-date-picker
                  v-model="creatPro.cycle"
                  style="width:100%"
                  type="daterange"
                  range-separator="至"
                  start-placeholder="开始日期"
                  end-placeholder="结束日期"
                ></el-date-picker>
              </el-form-item> -->
            </el-col>
          </el-row>
          <el-divider v-if="!isSign"></el-divider>
          <el-row :gutter="24" v-if="!isSign">
            <el-col :span="8">
              <el-form-item label="费用类型">
                <el-select style="width:100%" v-model="creatPro.costType">
                  <el-option
                    v-for="item in options"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="费用金额">
                <el-input placeholder="请输入金额" v-model="creatPro.amount" onkeyup="value=value.replace(/^\D*(\d*(?:\.\d{0,2})?).*$/g, '$1')">
                  <template slot="prepend">￥</template>
                  <template slot="append">元</template>
                </el-input>
              </el-form-item>
            </el-col>

            <el-col :span="8">
              <el-form-item label="费用周期">
                <el-date-picker
                  v-model="creatPro.costCycle"
                  style="width:100%"
                  type="daterange"
                  range-separator="至"
                  start-placeholder="开始日期"
                  end-placeholder="结束日期"
                ></el-date-picker>
              </el-form-item>
            </el-col>
          </el-row>
          <!-- 项目说明 输入长度限制20-->
          <el-form-item label="项目说明" prop="note">
            <el-input
              type="textarea"
              placeholder="项目说明（20字以内）"
              :rows="3"
              maxlength="20"
              v-model="creatPro.note"
            ></el-input>
          </el-form-item>
        </el-form>
        <el-form label-width="100px" v-if="isReview">
          <el-divider></el-divider>
          <el-form-item label="审批意见"  v-if="isReview">
            <el-input type="textarea" :rows="3" placeholder="审批意见(20字以内)" v-model="creatPro.note"></el-input>
          </el-form-item>
          <el-form-item label="优先级">
            <el-radio-group v-model="creatPro.flowPriority">
              <el-radio label="0">普通</el-radio>
              <el-radio label="1">重要</el-radio>
              <el-radio label="2">紧急</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="消息推送">
            <el-checkbox-group v-model="creatPro.msgPush">
              <el-checkbox label="1">站内消息通知</el-checkbox>
              <el-checkbox label="2">企业微信通知</el-checkbox>
              <el-checkbox label="3">邮件通知</el-checkbox>
            </el-checkbox-group>
          </el-form-item>
        </el-form>
        <div class="card-line">
          <!-- 立即申请 -->
          <el-button type="primary" size="small" @click="onSubmit" :disabled="isSubmit" v-if="isSetUp">立即申请</el-button>
          <!-- 重置 初始化表单数据 -->
          <el-button size="small" @click="save" :disabled="isSubmit" v-if="isSetUp">暂存草稿</el-button>
            <!-- 修改编辑 -->
          <el-button type="primary"  size="small" @click="edit" :disabled="isSubmit" v-if="isEditForm">修改编辑</el-button>
             <!-- 重置 初始化表单数据 -->
          <el-button type="success" size="small" @click="agreed" :disabled="isSubmit" v-if="isReview">通过</el-button>
            <!-- 修改编辑 -->
          <el-button type="warning"  size="small" @click="refused" :disabled="isSubmit" v-if="isReview">驳回</el-button>
          <!-- 打印 -->
          <el-button size="mini" icon="el-icon-printer" class="printBtn" v-if="isPrint" @click="prints">打印下载</el-button>
          <!-- 返回 -->
          <el-button class="clean-both" size="small" style="float:right" @click="goBack">返回</el-button>
          <div class="clean-both"></div>
        </div>
      </el-card>
    </div>
    <!-- 弹窗 立项报告 -->
    <el-dialog :visible.sync="dialogFormVisible" @close="goBack">
      <div id="single" class="single" ref="single">
        <h5 style="padding-top:0;">立项信息</h5>
        <table>
          <tbody>
            <tr>
              <td class="title">立项时间</td><td>{{ proInfo.createPro }}</td>
            </tr>
              <tr>
              <td class="title">归属部门</td><td>{{ proInfo.deptName }}</td>
            </tr>
            <tr>
              <td class="title">归属公司</td><td>{{ proInfo.compName }}</td>
            </tr>
            <tr>
              <td class="title">最终服务客户</td><td>{{ proInfo.cusName }}</td>
            </tr>
            <tr>
              <td class="title">最终服务客户部门</td><td>{{ proInfo.cusDeptName }}</td>
            </tr>
            <tr>
              <td class="title">项目名称</td><td>{{ proInfo.proName }}</td>
            </tr>
            <tr>
              <td class="title">项目经理</td><td>{{ proInfo.compDeptUser }}</td>
            </tr>
            <tr>
              <td class="title">项目类型</td><td>{{ proInfo.type }}</td>
            </tr>
            <tr>
              <td class="title">服务类型</td><td>{{ proInfo.serveType }}</td>
            </tr>
            <tr>
              <td class="title">项目计划开始时间</td><td>{{ proInfo.cycleStart }}</td>
            </tr>
            <tr>
              <td class="title">项目计划结束时间</td><td>{{ proInfo.cycleEnd }}</td>
            </tr>
            <tr>
              <td class="title">销售/交付负责人</td><td>{{ proInfo.saleUser }}</td>
            </tr>
            <tr>
              <td class="title">合同编号</td><td>{{ proInfo.contractCode }}</td>
            </tr>
            <tr>
              <td class="title">项目周期(月)</td><td>{{ proInfo.proCycle }}</td>
            </tr>
            <tr>
              <td class="title">计划投入人数</td><td>{{ proInfo.expectNum }}</td>
            </tr>
            <tr>
              <td class="title">计划投入人月</td><td>{{ proInfo.putInMonth }}</td>
            </tr>
            <tr>
              <td class="title">预估成本</td><td>{{ proInfo.ygCost }}</td>
            </tr>
            <tr>
              <td class="title">预估合同额</td><td>{{ proInfo.contractMoney }}</td>
            </tr>
            <tr>
              <td class="title">合同预计遣返时间</td><td>{{ proInfo.contractDate }}</td>
            </tr>
            <tr>
              <td class="title">立项说明</td><td>{{ proInfo.note }}</td>
            </tr>
            <tr>
              <td class="title">费用类型</td><td>{{ proInfo.costType }}</td>
            </tr>
            <tr>
              <td class="title">预算金额</td><td>{{ proInfo.amount }}</td>
            </tr>
            <tr>
              <td class="title">费用周期开始时间</td><td>{{ proInfo.costCycleStart }}</td>
            </tr>
            <tr>
              <td class="title">费用周期结束时间</td><td>{{ proInfo.costCycleEnd }}</td>
            </tr>
          </tbody>
        </table>
        <h5>审批记录</h5>
        <table>
          <thead>
            <tr>
              <th class="title2" style="width: 110px;">处理人</th>
              <th class="title2" style="width: 130px;">处理时间</th>
              <th class="title2" style="width: 80px;">处理结果</th>
              <th class="title2" style="text-align:left;">审批意见</th>
            </tr>
          </thead>
          <tbody>
            <tr v-for="(item, index) in lhistory" :key="index">
              <td style="text-align:center;">{{ item.doUser }}</td>
              <td>{{ item.doTime }}</td>
              <td style="text-align:center;">{{ item.doResult }}</td>
              <td>{{ item.note }}</td>
            </tr>
          </tbody>
        </table>
      </div>
      <div slot="footer" class="tdialog-footer">
         <!-- 图片 -->
        <el-button size="mini" @click="downloadResult" style="float:left;">图片下载</el-button>
        <!-- 打印 -->
        <el-button size="mini" v-print="'single'" style="float:right;">报告打印</el-button>
        <div class="clean-both"></div>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import moment from 'moment';
// 引入html2Canvas
import html2canvas from 'html2canvas';
export default {
  watch: {
    'creatPro.cycleStart' (val, oldVal) {
      let _this = this;
      if (_this.creatPro.cycleEnd && val) {
        let sTime = moment(val).format('YYYY-MM-DD');
        let eTime = moment(_this.creatPro.cycleEnd).format('YYYY-MM-DD');
        let startTime = new Date(sTime).getTime();
        let endTime = new Date(eTime).getTime();
        let differenceNum = (endTime - startTime) / (24 * 3600 * 1000);
        let proCycleMonth = differenceNum / 365 * 12;
        _this.creatPro.proCycle = proCycleMonth.toFixed(2);
      } else {
        _this.creatPro.proCycle = '';
      }
    },
    'creatPro.cycleEnd' (val, oldVal) {
      let _this = this;
      if (_this.creatPro.cycleStart && val) {
        let sTime = moment(_this.creatPro.cycleStart).format('YYYY-MM-DD');
        let eTime = moment(val).format('YYYY-MM-DD');
        let startTime = new Date(sTime).getTime();
        let endTime = new Date(eTime).getTime();
        let differenceNum = (endTime - startTime) / (24 * 3600 * 1000);
        let proCycleMonth = differenceNum / 365 * 12;
        _this.creatPro.proCycle = proCycleMonth.toFixed(2);
      } else {
        _this.creatPro.proCycle = '';
      }
    },
    'creatPro.expectNum' (val, oldVal) {
      let _this = this;
      if (_this.creatPro.proCycle && val) {
        _this.creatPro.putInMonth = (_this.creatPro.proCycle * val).toFixed(2);
      }
    }
  },
  data () {
    return {
      // 项目类型是否为预投入
      isYTR: false,
      headerTitle: '我的申请',
      pathRouter: 'reqFlow',
      // 查看表单数据
      showDatas: false,
      // 是否申请
      isSetUp: true,
      // 是否修改
      isEditForm: false,

      // 是否审查
      isReview: false,
      // 是否打印
      isPrint: false,

      isSubmit: false,

      // 立项信息表单
      creatPro: {
        // 标记转签
        sign: 0,
        // 接收转签
        receive: 0,
        // 关联项目
        related: '',
        // 归属部门
        deptId: '',
        // 客户部门
        cusDeptCode: '',
        // 客户部门-回显
        cusDeptCodes: '',
        // 服务类型
        serveType: '',
        // 关联公司
        compId: '',
        // 归属公司
        compName: '',
        // 项目类型
        type: '',
        // 关联客户
        cusId: '',
        // 项目合同编号
        contractCode: '',
        // 项目名称
        proName: '',
        // 项目经理
        pmp: '',
        // 项目计划开始时间
        cycleStart: '',
        // 项目计划结束时间
        cycleEnd: '',
        // 销售/交付负责人
        saleUser: '',
        // 项目周期(月)
        proCycle: '',
        // 计划投入人数
        expectNum: '',
        // 计划投入人月
        putInMonth: '',
        // 预估成本
        ygCost: '',
        // 预估合同额
        contractMoney: '',
        // 合同预计遣返时间
        contractDate: '',
        // 项目周期
        cycle: '',
        // 费用类型
        costType: '',
        // 预算金额
        amount: '',
        // 费用周期
        costCycle: '',
        // 项目费用 - 备注说明
        msg: '',
        // 备注说明
        note: '',
        // 优先级
        flowPriority: '0',
        // 消息推送
        msgPush: []
      },

      // 是否关联项目
      isRelat: false,

      // 是否标记转签
      isSign: false,

      // 表单验证规则
      creatProRules: {
        compId: [{ required: true, message: '请选择归属公司', trigger: 'change' }],
        type: [{ required: true, message: '请选择项目类型', trigger: 'change' }],
        serveType: [{ required: true, message: '请选择服务类型', trigger: 'change' }],
        deptId: [{ required: true, message: '请选择归属部门', trigger: 'change' }],
        cusId: [{ required: true, message: '请选择最终服务客户', trigger: 'change' }],
        cusDeptCode: [{ required: true, message: '请选择最终服务客户部门', trigger: 'change' }],
        proName: [{ required: true, message: '请输入项目名称', trigger: 'blur' }],
        pmp: [{ required: true, message: '请选择项目经理', trigger: 'change' }],
        cycleStart: [{ required: true, message: '请选择项目计划开始时间', trigger: 'change' }],
        cycleEnd: [{ required: true, message: '请选择项目计划结束时间', trigger: 'change' }]
      },

      // 所有公司数据
      compList: [],

      // 所有客户数据
      cusList: [],

      // 所有用户信息
      users: [],

      // 所有转签项目数据
      signList: [],

      options: [{
        value: 'XSE',
        label: '预计销售额'
      }],

      // 所有员工数据
      usersAll: [],

      dialogFormVisible: false,

      // 项目信息
      proInfo: {},
      // 审批记录
      lhistory: [],

      // 模糊搜索
      restaurants: [],
      state: '',
      timeout: null,
      // 获取所属部门下拉数据
      deptIdList: [],
      cusDeptCodeList: []
    };
  },
  mounted () {
    this.restaurants = this.loadAll();
  },
  // 过滤器
  filters: {
  // 员工工号显示过滤
    filterName (value, params) {
      for (let i = params.length; i--;) {
        if (params[i].userId === value) {
          return params[i].userName + ' [' + value + ']';
        }
      }
    },
    // 审批结果显示过滤
    filterResult (value) {
      //  <!-- 处理结果 1.发起 2.通过 3.驳回 4.取消 -->
      if (value === 1) {
        return '发起';
      }
      if (value === 2) {
        return '通过';
      }
      if (value === 3) {
        return '驳回';
      }
      if (value === 4) {
        return '取消';
      }
    },

    filterTimes (value) {
      return moment(value).format('YYYY-MM-DD') === 'Invalid date' ? '' : moment(value).format('YYYY-MM-DD HH:mm:ss');
    }
  },
  methods: {
    // 选择项目类型时
    changeType (val) {
      let _this = this;
      if (val === 'YTR') {
        _this.isYTR = true;
      } else {
        _this.isYTR = false;
      }
    },
    // 图片下载
    downloadResult () {
      let _this = this;
      html2canvas(_this.$refs.single, {
        backgroundColor: '#fff'
      }).then(canvas => {
        let imgData = canvas.toDataURL('image/jpeg');
        _this.fileDownload(imgData);
      });
    },

    // 下载图片
    fileDownload (downloadUrl) {
      // let _this = this;
      let aLink = document.createElement('a');
      aLink.style.display = 'none';
      aLink.href = downloadUrl;
      aLink.download = '立项报告.png';
      // 触发点击-然后移除
      document.body.appendChild(aLink);
      aLink.click();
      document.body.removeChild(aLink);
    },

    // 员工工号显示过滤
    filterName: function (value) {
      let _this = this;
      let params = _this.usersAll;
      for (let i = params.length; i--;) {
        if (params[i].userId === value) {
          return params[i].userName + ' [' + value + ']';
        }
      }
    },
    // 审批结果显示过滤
    filterResult: function (value) {
      //  <!-- 处理结果 1.发起 2.通过 3.驳回 4.取消 -->
      if (value === 1) {
        return '发起';
      }
      if (value === 2) {
        return '通过';
      }
      if (value === 3) {
        return '驳回';
      }
      if (value === 4) {
        return '取消';
      }
    },
    // 时间过滤
    filterTimes: function (value) {
      return moment(value).format('YYYY-MM-DD') === 'Invalid date' ? '' : moment(value).format('YYYY-MM-DD HH:mm:ss');
    },
    // 获取所有员工数据
    getUsersAll () {
      let _this = this;
      let params = {
        status: ''
      };
      _this.$http.post('api/findAllBaseUsers', params).then(res => {
        let { code, datas } = res;
        if (code === 0) {
          for (let i = datas.length; i--;) {
            _this.usersAll.push({
              compName: datas[i].compName,
              deptName: datas[i].deptName,
              userId: datas[i].userId,
              userName: datas[i].userName
            });
          };
        }
      }).catch(err => {
        if (err === undefined) {
          _this.$message({
            message: '服务器响应异常！',
            type: 'error'
          });
          return false;
        }
      });
    },

    // 加载全部员工数据
    loadAll () {
      return this.usersAll;
    },

    // 自动检索匹配
    querySearchAsync (queryString, cb) {
      let _this = this;
      let restaurants = _this.restaurants;
      let results = queryString ? restaurants.filter(_this.createStateFilter(queryString)) : restaurants;
      clearTimeout(_this.timeout);
      _this.timeout = setTimeout(() => {
        cb(results);
      }, 300 * Math.random());
    },

    // 查询
    createStateFilter (queryString) {
      return (state) => {
        return (state.userName.indexOf(queryString) === 0);
      };
    },

    // 选中赋值
    handleSelect (item) {
      this.creatPro.pmp = item.userName + ' [' + item.userId + ']';
    },

    // 获取选中用户信息
    selUser (data) {
      this.getUser = data;
      this.creatPro.pmp = data[0];
    },

    // 获取所有用户
    getUserList () {
      let _this = this;
      let params = {
        status: ''
      };
      _this.$http.post('api/findAllBaseUsers', params).then(res => {
        let { code, datas } = res;
        if (code === 0) {
          _this.users = datas;
        }
      }).catch(err => {
        if (err === undefined) {
          _this.$message({
            message: '服务器响应异常！',
            type: 'error'
          });
          return false;
        }
      });
    },

    // 查询所有公司
    getCompList () {
      this.$http.post('/api/findAllCompNoPage').then(res => {
        let {code, datas} = res;
        if (code === 0) {
          this.compList = datas;
        }
      }).catch(err => {
        if (err === undefined) {
          this.$message({
            message: '服务器响应异常！',
            type: 'error'
          });
          return false;
        }
      });
    },

    // 查询所有客户
    getCusList () {
      this.$http.post('/api/findAllCus').then(res => {
        let {code, datas} = res;
        if (code === 0) {
          this.cusList = datas;
        }
      }).catch(err => {
        if (err === undefined) {
          this.$message({
            message: '服务器响应异常！',
            type: 'error'
          });
          return false;
        }
      });
    },

    // 查询所有转签项目
    getSignList () {
      this.$http.post('/api/findAllSignPro').then(res => {
        let {code, datas} = res;
        if (code === 0) {
          this.signList = datas;
        }
      }).catch(err => {
        if (err === undefined) {
          this.$message({
            message: '服务器响应异常！',
            type: 'error'
          });
          return false;
        }
      });
    },

    // 是否接收转签
    isRelated () {
      if (this.creatPro.receive === 1) {
        this.isRelat = true;
        // this.$refs['creatPro'].resetFields();
      } else {
        this.isRelat = false;
        // this.$refs['creatPro'].resetFields();
      }
    },

    // 是否标记转签
    isSigned () {
      if (this.creatPro.sign === 1) {
        this.isSign = true;
        // this.$refs['creatPro'].resetFields();
        this.creatProRules = {
          compId: [{ required: true, message: '请选择归属公司', trigger: 'change' }],
          type: [{ required: true, message: '请选择项目类型', trigger: 'change' }],
          serveType: [{ required: true, message: '请选择服务类型', trigger: 'change' }],
          deptId: [{ required: true, message: '请选择归属部门', trigger: 'change' }],
          cusId: [{ required: true, message: '请选择最终服务客户', trigger: 'change' }],
          cusDeptCode: [{ required: true, message: '请选择最终服务客户部门', trigger: 'change' }],
          proName: [{ required: true, message: '请输入项目名称', trigger: 'blur' }],
          pmp: [{ required: true, message: '请选择项目经理', trigger: 'change' }],
          cycleStart: [{ required: true, message: '请选择项目计划开始时间', trigger: 'change' }],
          cycleEnd: [{ required: true, message: '请选择项目计划结束时间', trigger: 'change' }]
        };
      } else {
        this.isSign = false;
        // this.$refs['creatPro'].resetFields();
        this.creatProRules = {
          compId: [{ required: true, message: '请选择归属公司', trigger: 'change' }],
          type: [{ required: true, message: '请选择项目类型', trigger: 'change' }],
          serveType: [{ required: true, message: '请选择服务类型', trigger: 'change' }],
          deptId: [{ required: true, message: '请选择归属部门', trigger: 'change' }],
          cusId: [{ required: true, message: '请选择最终服务客户', trigger: 'change' }],
          cusDeptCode: [{ required: true, message: '请选择最终服务客户部门', trigger: 'change' }],
          proName: [{ required: true, message: '请输入项目名称', trigger: 'blur' }],
          pmp: [{ required: true, message: '请选择项目经理', trigger: 'change' }],
          cycleStart: [{ required: true, message: '请选择项目计划开始时间', trigger: 'change' }],
          cycleEnd: [{ required: true, message: '请选择项目计划结束时间', trigger: 'change' }]
        };
      }
    },

    // 清空立项
    reset () {
      this.$refs['creatPro'].resetFields();
    },

    // 拒绝申请
    refused: function () {
      let row = this.$route.query.datas;
      let _this = this;
      // 工单编号
      let flowCode = row.flowCode;
      // 驳回直接退回到申请人
      let logUser = row.flowOriginator;

      // 收集请求参数
      let userResult = {
        orderCode: flowCode,
        userId: logUser
      };
      // 根据操作历史回溯发起人、发起节点
      _this.$http.raw('/api/findResults', userResult).then(res => {
        let { code, datas } = res;
        if (code === 0) {
          // 发起节点
          let setUpNodeId = [];
          datas.map(item => {
            if (item.result === 1 && item.note === '发起申请') {
              setUpNodeId.push(item.flowNode);
            }
          });

          let params = {
            // 工单编号
            flowCode: row.flowCode,
            // 发起人
            flowOriginator: row.flowOriginator,
            // 当前审批节点
            flowCurrentNode: setUpNodeId[0],
            // 当前审批人
            flowCurrentUser: row.flowOriginator,
            // 工单状态
            status: 5,
            // 处理结果
            result: row.flowCurrentNode + ', 申请被驳回！',
            // 工单优先级
            flowPriority: this.creatPro.flowOriginator,
            // 消息推送
            msgPush: this.creatPro.msgPush.join(','),
            // 审批历史-审批节点
            flowNode: row.flowCurrentNode,
            // 审批历史-审批意见
            note: this.creatPro.note,
            // 审批历史-审批结果
            workResult: 3
          };

          this.$http.raw('api/updateOrderStatus', params).then(res => {
            let { code } = res;
            // 判断Code状态
            if (code === 0) {
              this.$message({
                message: '审批成功，已驳回申请！',
                type: 'success'
              });
              this.goBack();
            }
          }).catch(err => {
            if (err === undefined) {
              this.$message({
                message: '服务器响应异常！',
                type: 'error'
              });
              return false;
            }
          });
        }
      }).catch(err => {
        if (err === undefined) {
          this.$message({
            message: '服务器响应异常！',
            type: 'error'
          });
          return false;
        }
      });
    },

    // 通过申请
    agreed: function () {
      let _this = this;
      let row = _this.$route.query.datas;
      // 当前登录人信息
      // let user = _this.$store.state.userinfo;
      // 判断下一步审批节点
      // 判断当前审批节点 业务审批 | 财务审批
      let flowId = row.flowId;
      let prevNode = row.flowCurrentNode;

      // 申请通过判断当前节点的下一步审批节点
      let params = {
        prevNode,
        flowId
      };
      _this.$http.post('/api/findNextNode', params).then(res => {
        let {code, datas} = res;
        if (code === 0) {
          if (code === 0) {
            if (datas.flowType === '结束') {
              _this.goNextEnd(row);
            } else {
              _this.toNextNode(row, datas);
            }
          }
        }
      }).catch(err => {
        if (err === undefined) {
          this.$message({
            message: '服务器响应异常！',
            type: 'error'
          });
          return false;
        }
      });
    },

    // 正常业务线审批
    toNextNode (row, nextNode) {
      let _this = this;
      let rowDB = JSON.parse(row.formJson);
      // 部门
      let deptId = rowDB.compDeptUser.code[1];
      let deptRole = {
        deptId
      };
      let nextInfo = nextNode;
      // 判断是否存在审批角色池
      _this.$http.raw('/api/findUserRoles', deptRole).then(res => {
        let { code, datas } = res;
        // 判断Code状态
        if (code === 0) {
          let userLines = {};
          datas.map(item => {
            if (nextInfo.flowNodeRole === item.roleName) {
              userLines = item;
            }
          });
          let params = {
            // 工单编号
            flowCode: row.flowCode,
            // 发起人
            flowOriginator: row.flowOriginator,
            // 当前审批节点
            flowCurrentNode: nextInfo.flowNodeId,
            // 当前审批人
            flowCurrentUser: userLines.userId,
            // 工单状态
            status: 3,
            // 处理结果
            result: row.flowCurrentNode + ', 审批已通过！',
            // 工单优先级
            flowPriority: _this.creatPro.flowPriority,
            // 消息推送
            msgPush: _this.creatPro.msgPush.join(','),
            // 审批历史-审批节点
            flowNode: row.flowCurrentNode,
            // 审批历史-审批意见
            note: _this.creatPro.note,
            // 审批历史-审批结果
            workResult: 2
          };
          _this.$http.raw('api/updateOrderStatus', params).then(res => {
            let { code } = res;
            // 判断Code状态
            if (code === 0) {
              _this.$message({
                message: '审批成功，已批准通过！',
                type: 'success'
              });
              _this.goBack();
            }
          }).catch(err => {
            if (err === undefined) {
              _this.$message({
                message: '服务器响应异常！',
                type: 'error'
              });
              return false;
            }
          });
        }
      });
    },

    // 获取所有节点
    getNode () {
      let _this = this;
      // 初始数据源
      let nodeDB = _this.$route.query.datas;
      // 当前节点ID
      let node = _this.$route.query.node;

      if (node === 1) {
        _this.isSetUp = false;
        _this.isEditForm = true;
        let formDatas = JSON.parse(nodeDB.formJson);
        _this.isYTR = formDatas.type === 'YTR';
        _this.creatPro = formDatas;
        _this.creatPro.pmp = formDatas.tUserId;
        _this.creatPro.cusDeptCodes = formDatas.cusDeptCode;
        _this.creatPro.cusDeptCode = formDatas.cusDeptName;
        _this.$set(_this.creatPro, 'cycle', [formDatas.cycleStart, formDatas.cycleEnd]);
        _this.$set(_this.creatPro, 'costCycle', [formDatas.costCycleStart, formDatas.costCycleEnd]);
        _this.creatPro.flowPriority = nodeDB.flowPriority === null ? '' : nodeDB.flowPriority.toString();
        _this.creatPro.msgPush = nodeDB.msgPush.split(',');
        _this.isRelated();
        _this.isSigned();
      }
      if (node === 2 || node === 4 || node === 5 || node === 6) {
        this.isSetUp = false;
        this.showDatas = true;
        this.isPrint = node === 6;
        this.headerTitle = node === 2 ? '我的申请' : (node === 4 ? '我的已办' : (node === 5 ? '运行中流程' : '已结束流程'));
        this.pathRouter = node === 2 ? 'reqFlow' : (node === 4 ? 'doFlow' : (node === 5 ? 'flowing' : 'flowed'));
        let formDatas = JSON.parse(nodeDB.formJson);
        _this.isYTR = formDatas.type === 'YTR';
        _this.creatPro = formDatas;
        _this.creatPro.pmp = formDatas.tUserId;
        _this.creatPro.cusDeptCode = formDatas.cusDeptName;
        _this.$set(_this.creatPro, 'cycle', [formDatas.cycleStart, formDatas.cycleEnd]);
        _this.$set(_this.creatPro, 'costCycle', [formDatas.costCycleStart, formDatas.costCycleEnd]);
        _this.creatPro.flowPriority = nodeDB.flowPriority === null ? '' : nodeDB.flowPriority.toString();
        _this.creatPro.msgPush = nodeDB.msgPush.split(',');
        _this.isRelated();
        _this.isSigned();
      }
      if (node === 3) {
        this.isSetUp = false;
        this.isEditForm = false;
        this.showDatas = true;
        this.isReview = true;
        this.headerTitle = '我的待办';
        this.pathRouter = 'waitFlow';
        let formDatas = JSON.parse(nodeDB.formJson);
        _this.isYTR = formDatas.type === 'YTR';
        _this.creatPro = formDatas;
        _this.creatPro.pmp = formDatas.tUserId;
        _this.creatPro.cusDeptCode = formDatas.cusDeptName;
        _this.$set(_this.creatPro, 'cycle', [formDatas.cycleStart, formDatas.cycleEnd]);
        _this.$set(_this.creatPro, 'costCycle', [formDatas.costCycleStart, formDatas.costCycleEnd]);
        _this.creatPro.flowPriority = nodeDB.flowPriority === null ? '' : nodeDB.flowPriority.toString();
        _this.creatPro.msgPush = nodeDB.msgPush.split(',');
        _this.isRelated();
        _this.isSigned();
      }
    },

    // 提交
    createPro (proId) {
      let _this = this;
      // 流程表单模型数据
      let nodeDB = _this.$route.query.datas;
      // 当前登录人信息
      let user = _this.$store.state.userinfo;
      let userId = _this.creatPro.pmp;
      if (userId.indexOf('[') && userId.indexOf(']')) {
        userId = userId.slice(userId.indexOf('[') + 1, userId.indexOf(']'));
      }
      // 收集请求数据
      let formDB = {
        // 单据编号
        formNo: 'LXSQD-HF-',
        // 流程申请日期
        flowDay: moment().format('YYYY-MM-DD HH:mm:ss'),
        // 申请人信息
        compDeptUser: {
          code: [user.compId, user.deptId, user.userId],
          value: user.compName + '>' + user.deptName + '>' + user.userName
        },
        // 标记转签
        sign: _this.creatPro.sign,
        // 接收转签
        receive: _this.creatPro.receive,
        // 关联项目
        related: _this.creatPro.related,
        // 关联公司
        compId: _this.creatPro.compId,
        // 关联公司名称
        // compName: '浩方信息',
        // 项目类型
        type: _this.creatPro.type,
        // 服务类型
        serveType: _this.creatPro.serveType,
        // 关联客户
        cusId: _this.creatPro.cusId,
        // 归属部门ID
        deptId: _this.creatPro.deptId,
        // 客户部门
        cusDeptCode: _this.creatPro.cusDeptCode.split('-')[0],
        // 客户部门--回显
        cusDeptName: _this.creatPro.cusDeptCode.split('-')[1],
        // 项目合同编号
        contractCode: _this.creatPro.contractCode,
        // 项目名称
        proName: _this.creatPro.proName,
        // 项目经理
        pmp: userId,
        // 项目周期 - 开始时间
        cycleStart: _this.creatPro.cycleStart,
        // 项目周期 - 结束时间
        cycleEnd: _this.creatPro.cycleEnd,
        // 项目周期
        cycle: _this.creatPro.cycle,
        // 销售/交付负责人
        saleUser: _this.creatPro.saleUser,
        // 项目周期(月)
        proCycle: _this.creatPro.proCycle,
        // 计划投入人数
        expectNum: _this.creatPro.expectNum,
        // 计划投入人月
        putInMonth: _this.creatPro.putInMonth,
        // 预估成本
        ygCost: _this.creatPro.ygCost,
        // 预估合同额
        contractMoney: _this.creatPro.contractMoney,
        // 合同预计遣返时间
        contractDate: _this.creatPro.contractDate,
        // 费用类型
        costType: _this.creatPro.costType,
        // 预算金额
        amount: _this.creatPro.amount,
        // 费用周期 - 开始时间
        costCycleStart: _this.creatPro.costCycle[0],
        // 费用周期 - 结束时间
        costCycleEnd: _this.creatPro.costCycle[1],
        // 项目费用 - 备注说明
        msg: _this.creatPro.msg,
        // 备注说明
        note: _this.creatPro.note,
        // 项目经理 - 回显
        tUserId: _this.creatPro.pmp,
        // 优先级
        flowPriority: _this.creatPro.flowPriority,
        // 消息推送
        msgPush: _this.creatPro.msgPush
      };
      let flow = JSON.parse(nodeDB.flowJson).nodes;
      // 判断申请人是否在审批节点内
      // 过滤申请人
      let roleNode = [];
      flow.map(item => {
        if (item.users !== undefined) {
          item.users.map(val => {
            if (val === user.userId) {
              roleNode.push(item);
            }
          });
        }
      });
      // 判断申请人是否在审批节点内
      if (roleNode.length > 0) {
        // 在审批节点内，返回当前节点审批人 （审批角色）
        let startNode = [];
        startNode.push(roleNode[0].id);
        // 根据流程模型编号，当前节点 查询下一审批节点
        let nextNode = {
          flowId: nodeDB.flowId,
          prevNode: startNode[0]
        };
        _this.$http.post('/api/findNextNode', nextNode).then(res => {
          let {code, datas} = res;
          if (code === 0) {
            let nextInfo = datas;
            // let nextNode = datas.flowNodeId;
            let role = datas.flowNodeRole;
            let user = datas.note;
            // 判断是否存在审批角色池
            if (role !== '' && role !== '无') {
              // 部门
              let deptId = user.deptId;
              let deptRole = {
                deptId
              };
              // 获取当前申请人部门所有审批角色
              _this.$http.raw('/api/findUserRoles', deptRole).then(res => {
                let {code, datas} = res;
                if (code === 0) {
                  let nextUser = [];
                  datas.map(item => {
                    if (item.roleName === nextInfo.flowNodeRole) {
                      nextUser.push(item.userId);
                    }
                  });
                  // 发起流程
                  _this.startFLow(proId, startNode[0], user.userId, nextInfo.flowNodeId, nextUser.join(','), JSON.stringify(formDB));
                }
              }).catch(err => {
                if (err === undefined) {
                  _this.$message({
                    message: '服务器响应异常！',
                    type: 'error'
                  });
                  return false;
                }
              });
            } else {
              if (datas.flowType === '结束') {
                let flowCurrentNode = datas.flowNodeId;
                _this.toNextEnd(proId, startNode[0], user.userId, flowCurrentNode, JSON.stringify(formDB));
              } else {
                let flowCurrentNode = datas.flowNodeId;
                let flowCurrentUser = [];
                flow.map(item => {
                  if (item.id === flowCurrentNode) {
                    flowCurrentUser = item.users;
                  }
                });
                // 发起流程
                _this.startFLow(proId, startNode[0], user.userId, flowCurrentNode, flowCurrentUser.join(','), JSON.stringify(formDB));
              }
            }
          }
        }).catch(err => {
          if (err === undefined) {
            this.$message({
              message: '服务器响应异常！',
              type: 'error'
            });
            return false;
          }
        });
      } else {
        // 当前申请人是否在审批角色池内
        let nowNode = [];
        // 部门
        let deptId = user.deptId;
        let deptRole = {
          deptId
        };
        // 获取当前申请人部门所有审批角色
        _this.$http.raw('/api/findUserRoles', deptRole).then(res => {
          let { code, datas } = res;
          if (code === 0) {
            datas.map(item => {
              if (item.userId === user.userId) {
                nowNode.push(item.roleName);
              }
            });
            // 当前申请人是否在角色池内
            if (nowNode.length > 0) {
              let newId = '';
              flow.map(item => {
                if (item.roles === nowNode[0]) {
                  newId = item.id;
                }
              });
              let params = {
                flowId: nodeDB.flowId,
                prevNode: newId
              };
              _this.$http.post('/api/findNextNode', params).then(res => {
                let { code, datas } = res;
                if (code === 0) {
                  let nextInfo = datas;
                  // // let nextNode = datas.flowNodeId;
                  let role = datas.flowNodeRole;
                  // let users = datas.note;
                  // 判断是否存在审批角色池
                  if (role !== '' && role !== '无') {
                    // 部门
                    let deptId = user.deptId;
                    let deptRole = {
                      deptId
                    };
                    // 获取当前申请人部门所有审批角色
                    _this.$http.raw('/api/findUserRoles', deptRole).then(res => {
                      let {code, datas} = res;
                      if (code === 0) {
                        let nextUser = [];
                        datas.map(item => {
                          if (item.roleName === nextInfo.flowNodeRole) {
                            nextUser.push(item.userId);
                          }
                        });
                        // 发起流程
                        _this.startFLow(proId, newId, user.userId, nextInfo.flowNodeId, nextUser.join(','), JSON.stringify(formDB));
                      }
                    }).catch(err => {
                      if (err === undefined) {
                        _this.$message({
                          message: '服务器响应异常！',
                          type: 'error'
                        });
                        return false;
                      }
                    });
                  } else {
                    if (datas.flowType === '结束') {
                      let flowCurrentNode = datas.flowNodeId;
                      _this.toNextEnd(proId, newId, user.userId, flowCurrentNode, JSON.stringify(formDB));
                    } else {
                      let flowCurrentNode = datas.flowNodeId;
                      let flowCurrentUser = [];
                      flow.map(item => {
                        if (item.id === flowCurrentNode) {
                          flowCurrentUser = item.users;
                        }
                      });
                      // 发起流程
                      _this.startFLow(proId, newId, user.userId, flowCurrentNode, flowCurrentUser.join(','), JSON.stringify(formDB));
                    }
                  }
                }
              });
            } else {
              // 不在审批节点内，返回当前节点审批人 （默认：开始节点）
              let startNode = [];
              flow.map(item => {
                if (item.type === '开始') {
                  startNode.push(item.id);
                }
              });
              // 根据流程模型编号，当前节点 查询下一审批节点
              let nextNode = {
                flowId: nodeDB.flowId,
                prevNode: startNode[0]
              };
              _this.$http.post('/api/findNextNode', nextNode).then(res => {
                let {code, datas} = res;
                if (code === 0) {
                  let nextInfo = datas;
                  // // let nextNode = datas.flowNodeId;
                  let role = datas.flowNodeRole;
                  // let users = datas.note;
                  // 判断是否存在审批角色池
                  if (role !== '' && role !== '无') {
                    // 部门
                    let deptId = user.deptId;
                    let deptRole = {
                      deptId
                    };
                    // 获取当前申请人部门所有审批角色
                    _this.$http.raw('/api/findUserRoles', deptRole).then(res => {
                      let {code, datas} = res;
                      if (code === 0) {
                        let nextUser = [];
                        datas.map(item => {
                          if (item.roleName === nextInfo.flowNodeRole) {
                            nextUser.push(item.userId);
                          }
                        });
                        // 发起流程
                        _this.startFLow(proId, startNode[0], user.userId, nextInfo.flowNodeId, nextUser.join(','), JSON.stringify(formDB));
                      }
                    }).catch(err => {
                      if (err === undefined) {
                        _this.$message({
                          message: '服务器响应异常！',
                          type: 'error'
                        });
                        return false;
                      }
                    });
                  } else {
                    if (datas.flowType === '结束') {
                      let flowCurrentNode = datas.flowNodeId;
                      _this.toNextEnd(proId, startNode[0], user.userId, flowCurrentNode, JSON.stringify(formDB));
                    } else {
                      let flowCurrentNode = datas.flowNodeId;
                      let flowCurrentUser = [];
                      flow.map(item => {
                        if (item.id === flowCurrentNode) {
                          flowCurrentUser = item.users;
                        }
                      });
                      // 发起流程
                      _this.startFLow(proId, startNode[0], user.userId, flowCurrentNode, flowCurrentUser.join(','), JSON.stringify(formDB));
                    }
                  }
                }
              }).catch(err => {
                if (err === undefined) {
                  this.$message({
                    message: '服务器响应异常！',
                    type: 'error'
                  });
                  return false;
                }
              });
            }
          }
        });
      }
    },

    // 发起流程
    startFLow (proId, startNode, startUser, nextNode, nextUser, formDB) {
      let _this = this;
      let nodeDB = _this.$route.query.datas;
      let params = {
        tblWorkOrder: {
          // 关联项目ID
          note: proId,
          // 关联流程ID
          flowId: nodeDB.flowId,
          // 流程JSON
          flowJson: nodeDB.flowJson,
          // 表单JSON
          formJson: formDB,
          // 工单当前处理节点
          flowCurrentNode: nextNode,
          // 工单当前处理人ID
          flowCurrentUser: nextUser,
          // 工单优先级
          flowPriority: _this.creatPro.flowPriority,
          // 流程工单发起人
          flowOriginator: _this.$store.state.userinfo.userId,
          // 流程工单发起时间
          flowOriginatorTime: new Date(),
          // 工单状态
          status: 2,
          // 工单处理结果
          result: '已发起',
          // 消息推送
          msgPush: _this.creatPro.msgPush.join(',')
        },
        tblWorkResult: {
          flowNode: startNode,
          note: '发起申请',
          result: 1
        }
      };
      _this.$http.raw('api/insertWorkOrder', params).then(res => {
        let { code } = res;
        // 判断Code状态
        if (code === 0) {
          _this.$message({
            message: '发起流程成功！',
            type: 'success'
          });
          _this.goBack();
        }
      }).catch(err => {
        if (err === undefined) {
          _this.$message({
            message: '服务器响应异常！',
            type: 'error'
          });
          return false;
        }
      });
    },

    // 创建无效项目
    onSubmit () {
      let _this = this;
      let userId = _this.creatPro.pmp;
      if (userId.indexOf('[') && userId.indexOf(']')) {
        userId = userId.slice(userId.indexOf('[') + 1, userId.indexOf(']'));
      }
      // 收集请求数据
      let params = {
        // 标记转签
        sign: _this.creatPro.sign,
        // 接收转签
        receive: _this.creatPro.receive,
        // 关联项目
        related: _this.creatPro.related,
        // 关联公司
        compId: _this.creatPro.compId,
        // 关联公司名称
        // compName: '浩方信息',
        // 项目类型
        type: _this.creatPro.type,
        // 服务类型
        serveType: _this.creatPro.serveType,
        // 关联客户
        cusId: _this.creatPro.cusId,
        // 归属部门ID
        deptId: _this.creatPro.deptId,
        // 客户部门
        cusDeptCode: _this.creatPro.cusDeptCode.split('-')[0],
        // 客户部门--回显
        cusDeptName: _this.creatPro.cusDeptCode.split('-')[1],
        // 项目合同编号
        contractCode: _this.creatPro.contractCode,
        // 项目名称
        proName: _this.creatPro.proName,
        // 项目经理
        pmp: userId,
        // 项目周期 - 开始时间
        cycleStart: _this.creatPro.cycleStart,
        // 项目周期 - 结束时间
        cycleEnd: _this.creatPro.cycleEnd,
        // 项目周期
        cycle: _this.creatPro.cycle,
        // 销售/交付负责人
        saleUser: _this.creatPro.saleUser,
        // 项目周期(月)
        proCycle: _this.creatPro.proCycle,
        // 计划投入人数
        expectNum: _this.creatPro.expectNum,
        // 计划投入人月
        putInMonth: _this.creatPro.putInMonth,
        // 预估成本
        ygCost: _this.creatPro.ygCost,
        // 预估合同额
        contractMoney: _this.creatPro.contractMoney,
        // 合同预计遣返时间
        contractDate: _this.creatPro.contractDate,
        // 费用类型
        costType: _this.creatPro.costType,
        // 预算金额
        amount: _this.creatPro.amount,
        // 费用周期 - 开始时间
        costCycleStart: _this.creatPro.costCycle[0],
        // 费用周期 - 结束时间
        costCycleEnd: _this.creatPro.costCycle[1],
        // 备注说明
        note: _this.creatPro.msg,
        // 是否有效
        mark: 0
      };

      this.$nextTick(() => {
        // 判断是否通过验证规则验证
        this.$refs['creatPro'].validate(valid => {
          if (valid) {
            // 添加项目
            this.$http.raw('api/insertPro', params).then(res => {
              let { code } = res;
              // 判断Code状态
              if (code === 0) {
                _this.createPro(res.datas);
              }
            }).catch(err => {
              if (err === undefined) {
                this.$message({
                  message: '服务器响应异常！',
                  type: 'error'
                });
                return false;
              }
            });
          }
        });
      });
    },

    // 正常审批结束
    goNextEnd (row) {
      let _this = this;
      let rowDB = JSON.parse(row.flowJson).nodes;
      let endNode = [];

      rowDB.map(item => {
        if (item.type === '结束') {
          endNode.push(item.id);
        }
      });

      let params = {
        // 工单编号
        flowCode: row.flowCode,
        // 发起人
        flowOriginator: row.flowOriginator,
        // 当前审批节点
        flowCurrentNode: endNode[0],
        // 当前审批人
        flowCurrentUser: '',
        // 工单状态
        status: 4,
        // 处理结果
        result: row.flowCurrentNode + ', 审批已通过并结束！',
        // 工单优先级
        flowPriority: '',
        // 消息推送
        msgPush: '',
        // 审批历史-审批节点
        flowNode: row.flowCurrentNode,
        // 审批历史-审批意见
        note: _this.creatPro.note,
        // 审批历史-审批结果
        workResult: 2
      };
      this.$http.raw('api/updateOrderStatus', params).then(res => {
        let { code } = res;
        // 判断Code状态
        if (code === 0) {
          // 审批结束修改关联项目ID mark状态
          // note: res.datas,
          let proMark = {
            mark: 1,
            proId: row.note
          };
          _this.$http.post('api/updateProMark', proMark).then(res => {
            let { code } = res;
            if (code === 0) {
              this.$message({
                message: '审批成功，已批准通过！',
                type: 'success'
              });
              // 获取项目基本信息
              let params = {
                proId: row.note
              };
              // 获取人天数据
              _this.$http.post('api/findProInfo', params).then(res => {
                let { code, datas } = res;
                if (code === 0) {
                  _this.proInfo = {
                    // 立项时间
                    createPro: moment(datas.proInfo.cycleStart).format('YYYY-MM-DD'),
                    // 归属公司
                    compName: datas.proInfo.compName,
                    // 归属部门
                    deptName: datas.proInfo.deptName,
                    // 客户名称
                    cusName: datas.proInfo.cusName,
                    // 客户部门
                    cusDeptName: datas.proInfo.cusDeptName,
                    // 项目经理
                    compDeptUser: datas.memberInfo[0].compName + '>' + datas.memberInfo[0].deptName + '>' + datas.memberInfo[0].userName + '[' + datas.memberInfo[0].userId + ']',
                    // 项目名称
                    proName: datas.proInfo.proName,
                    // 项目周期 - 开始时间
                    cycleStart: moment(datas.proInfo.cycleStart).format('YYYY-MM-DD'),
                    // 项目周期 - 结束时间
                    cycleEnd: moment(datas.proInfo.cycleEnd).format('YYYY-MM-DD'),
                    // 销售/交付负责人
                    saleUser: datas.proInfo.saleUser,
                    // 项目周期(月)
                    proCycle: datas.proInfo.proCycle,
                    // 计划投入人数
                    expectNum: datas.proInfo.expectNum,
                    // 计划投入人月
                    putInMonth: datas.proInfo.putInMonth,
                    // 预估成本
                    ygCost: datas.proInfo.ygCost,
                    // 预估合同额
                    contractMoney: datas.proInfo.contractMoney,
                    // 合同预计遣返时间
                    contractDate: datas.proInfo.contractDate,
                    // 项目周期
                    cycle: datas.proInfo.cycle,
                    // 立项说明
                    note: datas.proInfo.note
                  };

                  let flowInfo = {
                    flowCode: row.flowCode
                  };
                  _this.$http.post('api/findWorkResultList', flowInfo).then(res => {
                    let { code, datas } = res;
                    // 判断Code状态
                    if (code === 0) {
                      let logls = [];
                      for (let i = 0; i < datas.length; i++) {
                        logls.push({
                          doUser: _this.filterName(datas[i].createUserId),
                          doTime: _this.filterTimes(datas[i].createTime),
                          doResult: _this.filterResult(datas[i].result),
                          note: datas[i].note
                        });
                      }

                      _this.lhistory = logls;
                      // _this.dialogFormVisible = true;

                      // setTimeout(() => {
                      //   // 通过页面生成立项报告并上传
                      //   html2canvas(_this.$refs.single, {
                      //     backgroundColor: '#fff'
                      //   }).then(canvas => {
                      //     let imgData = canvas.toDataURL('image/jpeg');
                      //     let formData = new FormData(); // 创建form对象
                      //     formData.append('base64', imgData);
                      //     _this.$http.upload('api/uploadFileBase64', formData).then(res => {
                      //       let { code, datas } = res;
                      //       if (code === 0) {
                      //         // 上传成功后添加立项报告记录
                      //         let inReport = {
                      //           // 立项报告文件路径
                      //           picUrl: datas,
                      //           // 审批记录
                      //           pJson: JSON.stringify(_this.lhistory),
                      //           // 关联项目ID
                      //           proId: row.note,
                      //           // 备注说明
                      //           note: ''
                      //         };
                      //         _this.$http.raw('api/insertProReport', inReport).then(res => {
                      //           let {code} = res;
                      //           if (code === 0) {
                      //             console.log('添加立项报告成功');
                      //           }
                      //         }).catch(err => {
                      //           if (err === undefined) {
                      //             _this.$message({
                      //               message: '服务器响应异常！',
                      //               type: 'error'
                      //             });
                      //             return false;
                      //           }
                      //         });
                      //       }
                      //     }).catch(err => {
                      //       if (err === undefined) {
                      //         _this.$message({
                      //           message: '服务器响应异常！',
                      //           type: 'error'
                      //         });
                      //         return false;
                      //       }
                      //     });
                      //   });
                      // }, 2000);
                    }
                  }).catch(err => {
                    if (err === undefined) {
                      _this.$message({
                        message: '服务器响应异常！',
                        type: 'error'
                      });
                      return false;
                    }
                  });
                }
              }).catch(err => {
                if (err === undefined) {
                  _this.$message({
                    message: '服务器响应异常！',
                    type: 'error'
                  });
                  return false;
                }
              });
            }
          }).catch(err => {
            if (err === undefined) {
              this.$message({
                message: '服务器响应异常！',
                type: 'error'
              });
              return false;
            }
          });
        }
      }).catch(err => {
        if (err === undefined) {
          this.$message({
            message: '服务器响应异常！',
            type: 'error'
          });
          return false;
        }
      });
    },

    // 发起审批并结束
    toNextEnd (proId, startNode, startUser, nextNode, formDB) {
      let _this = this;
      let nodeDB = _this.$route.query.datas;
      let params = {
        tblWorkOrder: {
          // 关联项目ID
          note: proId,
          // 工单编号
          flowCode: nodeDB.flowId + moment().format('YYYMMDDHHmmss'),
          // 关联流程ID
          flowId: nodeDB.flowId,
          // 流程JSON
          flowJson: nodeDB.flowJson,
          // 表单JSON
          formJson: formDB,
          // 工单当前处理节点
          flowCurrentNode: nextNode.toString(),
          // 工单当前处理人ID
          flowCurrentUser: '',
          // 工单优先级
          flowPriority: this.creatPro.flowPriority,
          // 流程工单发起人
          flowOriginator: startUser,
          // 流程工单发起时间
          flowOriginatorTime: new Date(),
          // 工单状态
          status: 4,
          // 工单处理结果
          result: '已发起并通过审批！',
          // 消息推送
          msgPush: this.creatPro.msgPush.toString()
        },
        tblWorkResult: {
          flowNode: startNode,
          note: '发起申请并通过审批！',
          result: 2
        }
      };
      this.$http.raw('api/insertWorkOrder', params).then(res => {
        let { code } = res;
        // 判断Code状态
        if (code === 0) {
          let flowCode = res.datas;
          let proMark = {
            mark: 1,
            proId: proId
          };
          _this.$http.post('api/updateProMark', proMark).then(res => {
            let { code } = res;
            if (code === 0) {
              this.$message({
                message: '审批成功，已批准通过！',
                type: 'success'
              });
              // 获取项目基本信息
              let params = {
                proId: proId
              };
              // 获取人天数据
              _this.$http.post('api/findProInfo', params).then(res => {
                let { code, datas } = res;
                if (code === 0) {
                  _this.proInfo = {
                    // 立项时间
                    createPro: moment(datas.proInfo.cycleStart).format('YYYY-MM-DD'),
                    // 所属公司
                    compName: datas.proInfo.compName,
                    // 归属部门名称
                    deptName: datas.proInfo.deptName,
                    // 客户名称
                    cusName: datas.proInfo.cusName,
                    // 客户部门
                    cusDeptName: datas.proInfo.cusDeptName,
                    // 项目经理
                    compDeptUser: datas.memberInfo[0].compName + '>' + datas.memberInfo[0].deptName + '>' + datas.memberInfo[0].userName + '[' + datas.memberInfo[0].userId + ']',
                    // 项目名称
                    proName: datas.proInfo.proName,
                    // 项目周期 - 开始时间
                    cycleStart: moment(datas.proInfo.cycleStart).format('YYYY-MM-DD'),
                    // 项目周期 - 结束时间
                    cycleEnd: moment(datas.proInfo.cycleEnd).format('YYYY-MM-DD'),
                    // 销售/交付负责人
                    saleUser: datas.proInfo.saleUser,
                    // 项目周期(月)
                    proCycle: datas.proInfo.proCycle,
                    // 计划投入人数
                    expectNum: datas.proInfo.expectNum,
                    // 计划投入人月
                    putInMonth: datas.proInfo.putInMonth,
                    // 预估成本
                    ygCost: datas.proInfo.ygCost,
                    // 预估合同额
                    contractMoney: datas.proInfo.contractMoney,
                    // 合同预计遣返时间
                    contractDate: datas.proInfo.contractDate,
                    // 项目周期
                    cycle: datas.proInfo.cycle,
                    // 立项说明
                    note: datas.proInfo.note
                  };

                  let flowInfo = {
                    flowCode: flowCode
                  };
                  _this.$http.post('api/findWorkResultList', flowInfo).then(res => {
                    let { code, datas } = res;
                    // 判断Code状态
                    if (code === 0) {
                      let logls = [];
                      for (let i = 0; i < datas.length; i++) {
                        logls.push({
                          doUser: _this.filterName(datas[i].createUserId),
                          doTime: _this.filterTimes(datas[i].createTime),
                          doResult: _this.filterResult(datas[i].result),
                          note: datas[i].note
                        });
                      }

                      _this.lhistory = logls;

                      // _this.dialogFormVisible = true;

                      // setTimeout(() => {
                      //   // 通过页面生成立项报告并上传
                      //   html2canvas(_this.$refs.single, {
                      //     backgroundColor: '#fff'
                      //   }).then(canvas => {
                      //     let imgData = canvas.toDataURL('image/jpeg');
                      //     let formData = new FormData(); // 创建form对象
                      //     formData.append('base64', imgData);
                      //     _this.$http.upload('api/uploadFileBase64', formData).then(res => {
                      //       let { code, datas } = res;
                      //       if (code === 0) {
                      //         // 上传成功后添加立项报告记录
                      //         let inReport = {
                      //           // 立项报告文件路径
                      //           picUrl: datas,
                      //           // 审批记录
                      //           pJson: JSON.stringify(_this.lhistory),
                      //           // 关联项目ID
                      //           proId: proId,
                      //           // 备注说明
                      //           note: ''
                      //         };
                      //         _this.$http.raw('api/insertProReport', inReport).then(res => {
                      //           let {code} = res;
                      //           if (code === 0) {
                      //             console.log('添加立项报告成功');
                      //           }
                      //         }).catch(err => {
                      //           if (err === undefined) {
                      //             _this.$message({
                      //               message: '服务器响应异常！',
                      //               type: 'error'
                      //             });
                      //             return false;
                      //           }
                      //         });
                      //       }
                      //     }).catch(err => {
                      //       if (err === undefined) {
                      //         _this.$message({
                      //           message: '服务器响应异常！',
                      //           type: 'error'
                      //         });
                      //         return false;
                      //       }
                      //     });
                      //   });
                      // }, 2000);
                    }
                  }).catch(err => {
                    if (err === undefined) {
                      _this.$message({
                        message: '服务器响应异常！',
                        type: 'error'
                      });
                      return false;
                    }
                  });
                }
              }).catch(err => {
                if (err === undefined) {
                  _this.$message({
                    message: '服务器响应异常！',
                    type: 'error'
                  });
                  return false;
                }
              });
              // this.goBack();
            }
          }).catch(err => {
            if (err === undefined) {
              this.$message({
                message: '服务器响应异常！',
                type: 'error'
              });
              return false;
            }
          });
        }
      }).catch(err => {
        if (err === undefined) {
          this.$message({
            message: '服务器响应异常！',
            type: 'error'
          });
          return false;
        }
      });
    },

    // 数据暂存操作
    save () {
      this.$nextTick(() => {
        // 判断是否通过验证规则验证
        this.$refs['creatPro'].validate(valid => {
          if (valid) {
            let _this = this;
            // 流程表单模型数据
            let nodeDB = _this.$route.query.datas;
            // 当前登录人信息
            let user = _this.$store.state.userinfo;
            let userId = _this.creatPro.pmp;
            if (userId.indexOf('[') && userId.indexOf(']')) {
              userId = userId.slice(userId.indexOf('[') + 1, userId.indexOf(']'));
            }
            // 收集请求数据
            let formDB = {
              // 单据编号
              formNo: 'LXSQD-HF-',
              // 流程申请日期
              flowDay: moment().format('YYYY-MM-DD HH:mm:ss'),
              // 申请人信息
              compDeptUser: {
                code: [user.compId, user.deptId, user.userId],
                value: user.compName + '>' + user.deptName + '>' + user.userName
              },
              // 标记转签
              sign: _this.creatPro.sign,
              // 接收转签
              receive: _this.creatPro.receive,
              // 关联项目
              related: _this.creatPro.related,
              // 关联公司
              compId: _this.creatPro.compId,
              // 关联公司名称
              // compName: '浩方信息',
              // 项目类型
              type: _this.creatPro.type,
              // 关联客户
              cusId: _this.creatPro.cusId,
              // 归属部门ID
              deptId: _this.creatPro.deptId,
              // 客户部门
              cusDeptCode: _this.creatPro.cusDeptCode.split('-')[0],
              // 客户部门--回显
              cusDeptName: _this.creatPro.cusDeptCode.split('-')[1],
              // 项目合同编号
              contractCode: _this.creatPro.contractCode,
              // 项目名称
              proName: _this.creatPro.proName,
              // 项目经理
              pmp: userId,
              // 项目周期 - 开始时间
              cycleStart: _this.creatPro.cycleStart,
              // 项目周期 - 结束时间
              cycleEnd: _this.creatPro.cycleEnd,
              // 销售/交付负责人
              saleUser: _this.creatPro.saleUser,
              // 项目周期(月)
              proCycle: _this.creatPro.proCycle,
              // 计划投入人数
              expectNum: _this.creatPro.expectNum,
              // 计划投入人月
              putInMonth: _this.creatPro.putInMonth,
              // 预估成本
              ygCost: _this.creatPro.ygCost,
              // 预估合同额
              contractMoney: _this.creatPro.contractMoney,
              // 合同预计遣返时间
              contractDate: _this.creatPro.contractDate,
              // 项目周期
              cycle: _this.creatPro.cycle,
              // 费用类型
              costType: _this.creatPro.costType,
              // 预算金额
              amount: _this.creatPro.amount,
              // 费用周期 - 开始时间
              costCycleStart: _this.creatPro.costCycle[0],
              // 费用周期 - 结束时间
              costCycleEnd: _this.creatPro.costCycle[1],
              // 项目费用 - 备注说明
              msg: _this.creatPro.msg,
              // 备注说明
              note: _this.creatPro.note,
              // 项目经理 - 回显
              tUserId: _this.creatPro.pmp,
              // 优先级
              flowPriority: _this.creatPro.flowPriority,
              // 消息推送
              msgPush: _this.creatPro.msgPush
            };

            let flow = JSON.parse(nodeDB.flowJson).nodes;

            // 判断申请人是否在审批节点内
            // 过滤申请人
            let roleNode = [];
            flow.map(item => {
              if (item.users !== undefined) {
                item.users.map(val => {
                  if (val === user.userId) {
                    roleNode.push(item);
                  }
                });
              }
            });
            // 判断申请人是否在审批节点内
            if (roleNode.length > 0) {
              // 在审批节点内，返回当前节点审批人 （审批角色）
              let startNode = [];
              startNode.push(roleNode[0].id);
              // 暂存操作
              _this.startWait(startNode[0], formDB);
            } else {
              // 不在审批节点内，返回当前节点审批人 （默认：开始节点）
              let startNode = [];
              flow.map(item => {
                if (item.type === '开始') {
                  startNode.push(item.id);
                }
              });
              // 暂存操作
              _this.startWait(startNode[0], formDB);
            }
          }
        });
      });
    },

    // 数据暂存（当前节点，当前数据）
    startWait (waitNode, formDB) {
      let _this = this;
      let nodeDB = _this.$route.query.datas;
      // 当前登录人信息
      let user = _this.$store.state.userinfo;
      let params = {
        tblWorkOrder: {
          // 关联流程ID
          flowId: nodeDB.flowId,
          // 流程JSON
          flowJson: nodeDB.flowJson,
          // 表单JSON
          formJson: JSON.stringify(formDB),
          // 工单处理记录ID  审批记录表
          // workOrderRecord: '',
          // 工单当前处理节点
          flowCurrentNode: waitNode,
          // 工单当前处理人ID
          flowCurrentUser: user.userId,
          // 工单优先级
          flowPriority: _this.creatPro.flowPriority,
          // 流程工单发起人
          flowOriginator: '',
          // 流程工单发起时间
          flowOriginatorTime: new Date(),
          // 工单状态
          status: 1,
          // 工单处理结果
          result: '暂存草稿',
          // 消息推送
          msgPush: _this.creatPro.msgPush.join(',')
        }
      };

      this.$http.raw('api/insertWorkOrder', params).then(res => {
        let { code } = res;
        // 判断Code状态
        if (code === 0) {
          this.$message({
            message: '已保存草稿！',
            type: 'success'
          });
          this.goBack();
        }
      }).catch(err => {
        if (err === undefined) {
          this.$message({
            message: '服务器响应异常！',
            type: 'error'
          });
          return false;
        }
      });
    },

    // 修改表单数据
    edit () {
      this.$nextTick(() => {
        // 判断是否通过验证规则验证
        this.$refs['creatPro'].validate(valid => {
          if (valid) {
            let _this = this;
            let row = _this.$route.query.datas;
            // 当前登录人信息
            let user = _this.$store.state.userinfo;
            let userId = _this.creatPro.pmp;
            if (userId.indexOf('[') && userId.indexOf(']')) {
              userId = userId.slice(userId.indexOf('[') + 1, userId.indexOf(']'));
            }
            let formItem = {
              // 单据编号
              formNo: 'LXSQD-' + user.compId + '-',
              // 流程申请日期
              flowDay: moment().format('YYYY-MM-DD HH:mm:ss'),
              // 申请人信息
              compDeptUser: {
                code: [user.compId, user.deptId, user.userId],
                value: user.compName + '>' + user.deptName + '>' + user.userName
              },
              // 标记转签
              sign: _this.creatPro.sign,
              // 接收转签
              receive: _this.creatPro.receive,
              // 关联项目
              related: _this.creatPro.related,
              // 关联公司
              compId: _this.creatPro.compId,
              // 关联公司名称
              // compName: '浩方信息',
              // 项目类型
              type: _this.creatPro.type,
              // 关联客户
              cusId: _this.creatPro.cusId,
              // 归属部门ID
              deptId: _this.creatPro.deptId,
              // 客户部门
              cusDeptCode: _this.creatPro.cusDeptCodes,
              // 客户部门--回显
              cusDeptName: _this.creatPro.cusDeptName,
              // 项目合同编号
              contractCode: _this.creatPro.contractCode,
              // 项目名称
              proName: _this.creatPro.proName,
              // 项目经理
              pmp: userId,
              // 项目周期 - 开始时间
              cycleStart: _this.creatPro.cycleStart,
              // 项目周期 - 结束时间
              cycleEnd: _this.creatPro.cycleEnd,
              // 销售/交付负责人
              saleUser: _this.creatPro.saleUser,
              // 项目周期(月)
              proCycle: _this.creatPro.proCycle,
              // 计划投入人数
              expectNum: _this.creatPro.expectNum,
              // 计划投入人月
              putInMonth: _this.creatPro.putInMonth,
              // 预估成本
              ygCost: _this.creatPro.ygCost,
              // 预估合同额
              contractMoney: _this.creatPro.contractMoney,
              // 合同预计遣返时间
              contractDate: _this.creatPro.contractDate,
              // 项目周期
              cycle: _this.creatPro.cycle,
              // 费用类型
              costType: _this.creatPro.costType,
              // 预算金额
              amount: _this.creatPro.amount,
              // 费用周期 - 开始时间
              costCycleStart: _this.creatPro.costCycle[0],
              // 费用周期 - 结束时间
              costCycleEnd: _this.creatPro.costCycle[1],
              // 项目费用 - 备注说明
              msg: _this.creatPro.msg,
              // 备注说明
              note: _this.creatPro.note,
              // 项目经理 - 回显
              tUserId: _this.creatPro.pmp,
              // 优先级
              flowPriority: _this.creatPro.flowPriority,
              // 消息推送
              msgPush: _this.creatPro.msgPush
            };
            let params = {
              flowCode: row.flowCode,
              // 表单JSON
              formJson: JSON.stringify(formItem),
              // 工单优先级
              flowPriority: _this.creatPro.flowPriority,
              // 消息推送
              msgPush: _this.creatPro.msgPush.join(',')
            };

            this.$http.post('api/updateWorkOrder', params).then(res => {
              let { code } = res;
              // 判断Code状态
              if (code === 0) {
                this.$message({
                  message: '已保存修改！',
                  type: 'success'
                });
                this.goBack();
              }
            }).catch(err => {
              if (err === undefined) {
                this.$message({
                  message: '服务器响应异常！',
                  type: 'error'
                });
                return false;
              }
            });
          }
        });
      });
    },

    // 返回上一步
    goBack () {
      this.$router.go(-1);
    },
    // 获取所属部门下拉数据
    getAllDeptData () {
      let _this = this;
      _this.$http.post('api/findDeptByCompNoPage').then(res => {
        let { code, datas } = res;
        // 判断Code状态
        if (code === 0) {
          // 所有部门数据赋值
          _this.deptIdList = datas;
        }
      }).catch(err => {
        if (err === undefined) {
          _this.$message({
            message: '服务器响应异常！',
            type: 'error'
          });
          return false;
        }
      });
    },
    // 选择客户名称关联客户部门
    selectDeptCode () {
      let _this = this;
      let params = {
        cusId: _this.creatPro.cusId
      };
      _this.$http.post('api/findCusDeptByCusId', params).then(res => {
        let { code, datas } = res;
        if (code === 0) {
          _this.cusDeptCodeList = datas;
        } else {
          return true;
        }
      }).catch(err => {
        if (err === undefined) {
          this.$message({
            message: '服务器响应异常！',
            type: 'error'
          });
          return false;
        }
      });
    },

    // 打印单据事件
    prints () {
      let _this = this;
      let row = _this.$route.query.datas;
      _this.dialogFormVisible = true;
      // 获取项目基本信息
      let params = {
        proId: row.note
      };
      // 获取人天数据
      _this.$http.post('api/findProInfo', params).then(res => {
        let { code, datas } = res;
        if (code === 0) {
          _this.proInfo = {
            // 立项时间
            createPro: moment(datas.proInfo.cycleStart).format('YYYY-MM-DD'),
            // 归属公司
            compName: datas.proInfo.compName,
            // 归属部门
            deptName: datas.proInfo.deptName,
            // 客户名称
            cusName: datas.proInfo.cusName,
            // 客户部门
            cusDeptName: datas.proInfo.cusDeptName,
            // 项目经理
            compDeptUser: datas.memberInfo[0].compName + '>' + datas.memberInfo[0].deptName + '>' + datas.memberInfo[0].userName + '[' + datas.memberInfo[0].userId + ']',
            // 项目名称
            proName: datas.proInfo.proName,
            // 项目类型
            type: datas.proInfo.type,
            // 服务类型
            serveType: datas.proInfo.serveType,
            // 合同编号
            contractCode: datas.proInfo.contractCode,
            // 项目周期 - 开始时间
            cycleStart: moment(datas.proInfo.cycleStart).format('YYYY-MM-DD'),
            // 项目周期 - 结束时间
            cycleEnd: moment(datas.proInfo.cycleEnd).format('YYYY-MM-DD'),
            // 销售/交付负责人
            saleUser: datas.proInfo.saleUser,
            // 项目周期(月)
            proCycle: datas.proInfo.proCycle,
            // 计划投入人数
            expectNum: datas.proInfo.expectNum,
            // 计划投入人月
            putInMonth: datas.proInfo.putInMonth,
            // 预估成本
            ygCost: datas.proInfo.ygCost,
            // 预估合同额
            contractMoney: datas.proInfo.contractMoney,
            // 合同预计遣返时间
            contractDate: datas.proInfo.contractDate,
            // 项目周期
            cycle: datas.proInfo.cycle,
            // 立项说明
            note: datas.proInfo.note
          };
        }
      });
      // _this.dialogFormVisible = true;

      // setTimeout(() => {
      //   // 通过页面生成立项报告并上传
      //   html2canvas(_this.$refs.single, {
      //     backgroundColor: '#fff'
      //   }).then(canvas => {
      //     let imgData = canvas.toDataURL('image/jpeg');
      //     let formData = new FormData(); // 创建form对象
      //     formData.append('base64', imgData);
      //     _this.$http.upload('api/uploadFileBase64', formData).then(res => {
      //       let { code, datas } = res;
      //       if (code === 0) {
      //         // 上传成功后添加立项报告记录
      //         let inReport = {
      //           // 立项报告文件路径
      //           picUrl: datas,
      //           // 审批记录
      //           pJson: JSON.stringify(_this.lhistory),
      //           // 关联项目ID
      //           proId: row.note,
      //           // 备注说明
      //           note: ''
      //         };
      //         _this.$http.raw('api/insertProReport', inReport).then(res => {
      //           let {code} = res;
      //           if (code === 0) {
      //             console.log('添加立项报告成功');
      //           }
      //         }).catch(err => {
      //           if (err === undefined) {
      //             _this.$message({
      //               message: '服务器响应异常！',
      //               type: 'error'
      //             });
      //             return false;
      //           }
      //         });
      //       }
      //     }).catch(err => {
      //       if (err === undefined) {
      //         _this.$message({
      //           message: '服务器响应异常！',
      //           type: 'error'
      //         });
      //         return false;
      //       }
      //     });
      //   });
      // }, 2000);
    }
  },
  created () {
    // 获取所属部门下拉数据
    this.getAllDeptData();
    // 获取所有用户
    // this.getUsers();

    // 查询所有公司
    this.getCompList();

    // 查询所有客户
    this.getCusList();

    // 获取所有员工
    // this.getUserList();

    this.getUsersAll();

    // 获取所有转签项目
    this.getSignList();

    // 获取节点数据
    this.getNode();
  }
};
</script>

<style lang="scss" scoped>
@import './index.scss';
</style>
<style lang="scss">
  .userlevel-box {
    .el-form-item__label {
      line-height: 20px;
    }
  }
</style>
